<?php
/**
 * Created by PhpStorm.
 * User: chenxiang
 * Date: 2017/4/27
 * Time: 09:11
 */

namespace App\Model;


use Illuminate\Database\Eloquent\SoftDeletes;

class Model extends \Illuminate\Database\Eloquent\Model
{
    use SoftDeletes;

    // 显示字段
    protected $fillable = [
    ];

    /**
     * The attributes that should be hidden for arrays.
     *
     * @var array
     */
    // 隐藏字段
    protected $hidden = [
    ];
    protected $dates = ['deleted_at'];

    // 只需要 定义 好 验证 方法 就 能直接使用
    static public function validate($data){
        $validate  =  self::_validate();
        foreach($validate as $key=>$val){
            if(!array_key_exists($key,$data)){
                unset($validate[$key]);
            }
        }
//        foreach($data as $key=>$val){
//            if(isset($validate[$key])){
//                $validate_tmp[$key] = $validate[$key];
//            }
//        }
        if(!$data || !$validate){
            return Json::error('验证字段或者参数为空');
        }
        $validator = validator($data,$validate);
        if($validator->fails()){
            return Json::error($validator->errors()->toArray());
        }
        return Json::success($data);
    }


}